/*    */ package com.newcrm.businessarchives;
/*    */ 
/*    */ import com.newcrm.exception.CaptchaException;
/*    */ import com.newcrm.util.Util;
/*    */ import java.io.IOException;
/*    */ import java.io.UnsupportedEncodingException;
/*    */ import java.net.URLEncoder;
/*    */ import java.util.Date;
/*    */ import java.util.HashMap;
/*    */ import java.util.Map;
/*    */ import org.apache.log4j.Logger;
/*    */ import org.jsoup.Connection;
/*    */ import org.jsoup.Jsoup;
/*    */ import org.jsoup.nodes.Document;
/*    */ import org.jsoup.nodes.Element;
/*    */ import org.jsoup.select.Elements;
/*    */ 
/*    */ public class GuangdongSearchEngine extends SearchEngine
/*    */ {
/* 21 */   private static Logger logger = Logger.getLogger(GuangdongSearchEngine.class
/* 22 */     .getName());
/*    */ 
/* 24 */   private Map<String, String> params = new HashMap();
/*    */ 
/*    */   public GuangdongSearchEngine(String name) {
/* 27 */     this.name = standardizedName(name);
/* 28 */     this.params.put("地    址：", "Address");
/* 29 */     this.params.put("注 册 号：", "SN");
/* 30 */     this.params.put("登记机关：", "RegistrationAuthority");
/* 31 */     this.params.put("企业类型：", "CompanyType");
/* 32 */     this.params.put("法定代表人：", "Header");
/* 33 */     this.params.put("注册资本：", "RegisteredCapital");
/* 34 */     this.params.put("经营期限：", "OperatingPeriod");
/* 35 */     this.params.put("企业状态：", "AnnualinSpectionResult");
/* 36 */     this.params.put("成立日期：", "FoundedDate");
/* 37 */     this.params.put("经营范围：", "BusinessScope");
/*    */   }
/*    */ 
/*    */   protected Map<String, Object> getCompanyByWeb()
/*    */     throws CaptchaException
/*    */   {
/* 43 */     if (!isValid(this.name)) {
/* 44 */       return null;
/*    */     }
/*    */ 
/* 48 */     String url = "";
/*    */     try {
/* 50 */       url = "http://wsnj.gdgs.gov.cn/aiccps/SearchServlet?service=getEntityInfoByPage&corpName=" + 
/* 51 */         URLEncoder.encode(this.name.trim(), "gb2312");
/*    */     } catch (UnsupportedEncodingException e) {
/* 53 */       url = "http://wsnj.gdgs.gov.cn/aiccps/SearchServlet?service=getEntityInfoByPage&corpName=" + this.name.trim();
/*    */     }
/*    */     try
/*    */     {
/* 57 */       Document doc = 
/* 58 */         Jsoup.connect(url)
/* 59 */         .header("Host", "wsnj.gdgs.gov.cn")
/* 60 */         .referrer(
/* 61 */         "http://wsnj.gdgs.gov.cn/aiccps/jsp/pub/searchBase.jsp")
/* 62 */         .userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(10000).get();
/* 63 */       Elements links = doc.select("table td[class^=P]");
/* 64 */       if (links == null) {
/* 65 */         return null;
/*    */       }
/*    */ 
/* 68 */       Map info = new HashMap();
/* 69 */       for (Element item : links) {
/* 70 */         String key = item.text().trim();
/* 71 */         if (this.params.containsKey(key))
/*    */         {
/* 74 */           info.put((String)this.params.get(key), item.nextElementSibling().html()
/* 75 */             .replace("&nbsp;", ""));
/*    */         }
/*    */       }
/* 78 */       if (info.size() > 1) {
/* 79 */         info.put("CompanyName", this.name);
/*    */       }
/* 81 */       info.put("UpdateDate", Util.date2Str(new Date()));
/* 82 */       if (info.size() > 2)
/*    */       {
/* 84 */         saveDB(info);
/*    */       }
/*    */ 
/* 87 */       return info;
/*    */     } catch (IOException e) {
/* 89 */       logger.warn("get company from web failed", e);
/*    */     }
/* 91 */     return null;
/*    */   }
/*    */ 
/*    */   public static void main(String[] args) {
/* 95 */     GuangdongSearchEngine e = new GuangdongSearchEngine("珠海佳力五金制品有限公司");
/*    */     try {
/* 97 */       e.getCompanyByWeb();
/*    */     }
/*    */     catch (CaptchaException e1) {
/* 100 */       e1.printStackTrace();
/*    */     }
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.businessarchives.GuangdongSearchEngine
 * JD-Core Version:    0.6.1
 */